﻿//========================================================= 
/**@file H002_ReaderDevAdapter.h
 * @brief H002设备设置指令适配器
 * 
 * @date 2016-03-11   21:15:24
 * @author Zhyioo 
 * @version 1.0
 */ 
//--------------------------------------------------------- 
#ifndef _LIBZHOUYB_H002_READERDEVADAPTER_H_
#define _LIBZHOUYB_H002_READERDEVADAPTER_H_
//--------------------------------------------------------- 
#include "../../include/Base.h"
#include "../../device/magnetic/MagneticDevAdapter.h"
using zhou_yb::device::magnetic::MagneticDevAdapter;
//--------------------------------------------------------- 
namespace zhou_yb {
namespace application {
namespace device {
//--------------------------------------------------------- 
/// H002设备控制器
class H002_ReaderDevAdapter : public DevAdapterBehavior<IInteractiveTrans>
{
public:
    /// Led模式
    enum LedMode
    {
        /// 打开
        LedOn,
        /// 关闭
        LedOff,
        /// 闪烁
        LedLight
    };
    /// Led模块
    enum LedModule
    {
        /// 非接触式IC Led
        LedContactless,
        /// 接触式IC Led
        LedContact,
        /// 磁条Led
        LedMagnetic,
        /// 指纹
        LedFinger
    };
    /// 生成Led控制字节
    static void MakeLed(LedModule module, LedMode mode, byte& ledMode)
    {
        switch(mode)
        {
        case LedOn:
            BitConvert::Set(ledMode, module, 1);
            BitConvert::Set(ledMode, module + 3, 0);
            break;
        case LedOff:
            BitConvert::Set(ledMode, module, 0);
            BitConvert::Set(ledMode, module + 3, 0);
            break;
        case LedLight:
            BitConvert::Set(ledMode, module, 1);
            BitConvert::Set(ledMode, module + 3, 1);
            break;
        }
    }
    /// Led控制器
    bool LedControl(byte ledMode)
    {
        LOG_FUNC_NAME();
        ASSERT_Device();
        LOGGER(_log << "LedMode:<" << _bit(ledMode) << ">\n");
        byte cmd[3] = { 0x1B, 0x50, 0x00 };
        cmd[2] = ledMode;
        ASSERT_FuncErr(_pDev->Write(ByteArray(cmd, 3)), DeviceError::SendErr);

        return _logRetValue(true);
    }
    /// 蜂鸣器
    bool BeepControl()
    {
        LOG_FUNC_NAME();
        ASSERT_Device();
        byte beepCmd[2] = { 0x1B, 'b' };
        return _logRetValue(_pDev->Write(ByteArray(beepCmd, 2)));
    }
};
//--------------------------------------------------------- 
} // namespace device
} // namespace application
} // namespace zhou_yb
//--------------------------------------------------------- 
#endif // _LIBZHOUYB_H002_READERDEVADAPTER_H_
//========================================================= 